<script>
// import html2canvas from 'html2canvas';
// import jsPDF from 'jspdf';
import { htmlToPdf, exportToPDF, downloadPDF } from '@/utils/htmlToPdf';
import * as echarts from 'echarts'; // 引入echarts库
export default {
    name: 'HtmlToPDF',
    data() {
        return {
            includeChart: true,
            tableData: [
                { name: 'John', age: 30, city: 'New York' },
                { name: 'Jane', age: 25, city: 'Los Angeles' },
                { name: 'Bob', age: 35, city: 'Chicago' },
                { name: 'Alice', age: 28, city: 'Houston' },
                { name: 'Mike', age: 32, city: 'Phoenix' },
                { name: 'Emily', age: 27, city: 'Philadelphia' },
                { name: 'David', age: 31, city: 'San Antonio' },
                { name: 'Sarah', age: 29, city: 'San Diego' },
                { name: 'Chris', age: 33, city: 'Dallas' },
                { name: 'Jessica', age: 26, city: 'San Jose' },
                { name: 'Daniel', age: 34, city: 'Austin' },
                { name: 'Olivia', age: 24, city: 'Jacksonville' },
                { name: 'James', age: 36, city: 'Fort Worth' },
                { name: 'Sophia', age: 23, city: 'Charlotte' },
                { name: 'Andrew', age: 37, city: 'Indianapolis' },
                { name: 'Emma', age: 22, city: 'San Francisco' },
                { name: 'Joseph', age: 38, city: 'Columbus' },
                { name: 'Ava', age: 21, city: 'Detroit' },
                { name: 'William', age: 39, city: 'El Paso' },
                { name: 'Isabella', age: 20, city: 'Memphis' },
                { name: 'Ethan', age: 40, city: 'Seattle' },
                { name: 'Mia', age: 19, city: 'Denver' },
                { name: 'Noah', age: 41, city: 'Washington' },
                { name: 'Charlotte', age: 18, city: 'Boston' },
                { name: 'Liam', age: 42, city: 'Nashville' },
                { name: 'Amelia', age: 17, city: 'Baltimore' },
                { name: 'Benjamin', age: 43, city: 'Louisville' },
                { name: 'Harper', age: 16, city: 'Milwaukee' },
                { name: 'Henry', age: 44, city: 'Portland' },
                { name: 'Evelyn', age: 15, city: 'Las Vegas' },
                { name: 'Alexander', age: 45, city: 'Oklahoma City' },
                { name: 'Abigail', age: 14, city: 'Albuquerque' },
                { name: 'Michael', age: 46, city: 'Tucson' },
                { name: 'Emily', age: 13, city: 'Fresno' },
                { name: 'Elijah', age: 47, city: 'Sacramento' },
                { name: 'Elizabeth', age: 12, city: 'Long Beach' },
                { name: 'James', age: 48, city: 'Kansas City' },
                { name: 'Sofia', age: 11, city: 'Mesa' },
                { name: 'Daniel', age: 49, city: 'Virginia Beach' },
                { name: 'Avery', age: 10, city: 'Atlanta' },
                { name: 'Matthew', age: 50, city: 'Colorado Springs' },
                { name: 'Ella', age: 9, city: 'Raleigh' },
                { name: 'Aiden', age: 51, city: 'Omaha' },
                { name: 'Scarlett', age: 8, city: 'Miami' },
                { name: 'Logan', age: 52, city: 'Tulsa' },
                { name: 'Victoria', age: 7, city: 'Oakland' },
                { name: 'Jackson', age: 53, city: 'Minneapolis' },
                { name: 'Madison', age: 6, city: 'Tampa' },
                { name: 'David', age: 54, city: 'Cleveland' },
                { name: 'Luna', age: 5, city: 'Wichita' },
                { name: 'Joseph', age: 55, city: 'Arlington' },
                { name: 'Chloe', age: 4, city: 'New Orleans' },
                { name: 'Samuel', age: 56, city: 'Bakersfield' },
                { name: 'Grace', age: 3, city: 'Trenton' },
                { name: 'Gabriel', age: 57, city: 'Cincinnati' },
                { name: 'Lily', age: 2, city: 'Aurora' },
                { name: 'Benjamin', age: 58, city: 'Rochester' },
                { name: 'Aria', age: 1, city: 'Riverside' },
                { name: 'John', age: 30, city: 'New York' },
                { name: 'Jane', age: 25, city: 'Los Angeles' },
                { name: 'Bob', age: 35, city: 'Chicago' },
                { name: 'Alice', age: 28, city: 'Houston' },
                { name: 'Mike', age: 32, city: 'Phoenix' },
                { name: 'Emily', age: 27, city: 'Philadelphia' },
                { name: 'David', age: 31, city: 'San Antonio' },
                { name: 'Sarah', age: 29, city: 'San Diego' },
                { name: 'Chris', age: 33, city: 'Dallas' },
                { name: 'Jessica', age: 26, city: 'San Jose' },
                { name: 'Daniel', age: 34, city: 'Austin' },
                { name: 'Olivia', age: 24, city: 'Jacksonville' },
                { name: 'James', age: 36, city: 'Fort Worth' },
                { name: 'Sophia', age: 23, city: 'Charlotte' },
                { name: 'Andrew', age: 37, city: 'Indianapolis' },
                { name: 'Emma', age: 22, city: 'San Francisco' },
                { name: 'Joseph', age: 38, city: 'Columbus' },
                { name: 'Ava', age: 21, city: 'Detroit' },
                { name: 'William', age: 39, city: 'El Paso' },
                { name: 'Isabella', age: 20, city: 'Memphis' },
                { name: 'Ethan', age: 40, city: 'Seattle' },
                { name: 'Mia', age: 19, city: 'Denver' },
                { name: 'Noah', age: 41, city: 'Washington' },
                { name: 'Charlotte', age: 18, city: 'Boston' },
                { name: 'Liam', age: 42, city: 'Nashville' },
                { name: 'Amelia', age: 17, city: 'Baltimore' },
                { name: 'Benjamin', age: 43, city: 'Louisville' },
                { name: 'Harper', age: 16, city: 'Milwaukee' },
                { name: 'Henry', age: 44, city: 'Portland' },
                { name: 'Evelyn', age: 15, city: 'Las Vegas' },
                { name: 'Alexander', age: 45, city: 'Oklahoma City' },
                { name: 'Abigail', age: 14, city: 'Albuquerque' },
                { name: 'Michael', age: 46, city: 'Tucson' },
                { name: 'Emily', age: 13, city: 'Fresno' },
                { name: 'Elijah', age: 47, city: 'Sacramento' },
                { name: 'Elizabeth', age: 12, city: 'Long Beach' },
                { name: 'James', age: 48, city: 'Kansas City' },
                { name: 'Sofia', age: 11, city: 'Mesa' },
                { name: 'Daniel', age: 49, city: 'Virginia Beach' },
                { name: 'Avery', age: 10, city: 'Atlanta' },
                { name: 'Matthew', age: 50, city: 'Colorado Springs' },
                { name: 'Ella', age: 9, city: 'Raleigh' },
                { name: 'Aiden', age: 51, city: 'Omaha' },
                { name: 'Scarlett', age: 8, city: 'Miami' },
                { name: 'Logan', age: 52, city: 'Tulsa' },
                { name: 'Victoria', age: 7, city: 'Oakland' },
                { name: 'Jackson', age: 53, city: 'Minneapolis' },
                { name: 'Madison', age: 6, city: 'Tampa' },
                { name: 'David', age: 54, city: 'Cleveland' },
                { name: 'Luna', age: 5, city: 'Wichita' },
                { name: 'Joseph', age: 55, city: 'Arlington' },
                { name: 'Chloe', age: 4, city: 'New Orleans' },
                { name: 'Samuel', age: 56, city: 'Bakersfield' },
                { name: 'Grace', age: 3, city: 'Trenton' },
                { name: 'Gabriel', age: 57, city: 'Cincinnati' },
                { name: 'Lily', age: 2, city: 'Aurora' },
                { name: 'Benjamin', age: 58, city: 'Rochester' },
                { name: 'Aria', age: 1, city: 'Riverside' },
                { name: 'John', age: 30, city: 'New York' },
                { name: 'Jane', age: 25, city: 'Los Angeles' },
                { name: 'Bob', age: 35, city: 'Chicago' },
                { name: 'Alice', age: 28, city: 'Houston' },
                { name: 'Mike', age: 32, city: 'Phoenix' },
                { name: 'Emily', age: 27, city: 'Philadelphia' },
                { name: 'David', age: 31, city: 'San Antonio' },
                { name: 'Sarah', age: 29, city: 'San Diego' },
                { name: 'Chris', age: 33, city: 'Dallas' },
                { name: 'Jessica', age: 26, city: 'San Jose' },
                { name: 'Daniel', age: 34, city: 'Austin' },
                { name: 'Olivia', age: 24, city: 'Jacksonville' },
                { name: 'James', age: 36, city: 'Fort Worth' },
                { name: 'Sophia', age: 23, city: 'Charlotte' },
                { name: 'Andrew', age: 37, city: 'Indianapolis' },
                { name: 'Emma', age: 22, city: 'San Francisco' },
                { name: 'Joseph', age: 38, city: 'Columbus' },
                { name: 'Ava', age: 21, city: 'Detroit' },
                { name: 'William', age: 39, city: 'El Paso' },
                { name: 'Isabella', age: 20, city: 'Memphis' },
                { name: 'Ethan', age: 40, city: 'Seattle' },
                { name: 'Mia', age: 19, city: 'Denver' },
                { name: 'Noah', age: 41, city: 'Washington' },
                { name: 'Charlotte', age: 18, city: 'Boston' },
                { name: 'Liam', age: 42, city: 'Nashville' },
                { name: 'Amelia', age: 17, city: 'Baltimore' },
                { name: 'Benjamin', age: 43, city: 'Louisville' },
                { name: 'Harper', age: 16, city: 'Milwaukee' },
                { name: 'Henry', age: 44, city: 'Portland' },
                { name: 'Evelyn', age: 15, city: 'Las Vegas' },
                { name: 'Alexander', age: 45, city: 'Oklahoma City' },
                { name: 'Abigail', age: 14, city: 'Albuquerque' },
                { name: 'Michael', age: 46, city: 'Tucson' },
                { name: 'Emily', age: 13, city: 'Fresno' },
                { name: 'Elijah', age: 47, city: 'Sacramento' },
                { name: 'Elizabeth', age: 12, city: 'Long Beach' },
                { name: 'James', age: 48, city: 'Kansas City' },
                { name: 'Sofia', age: 11, city: 'Mesa' },
                { name: 'Daniel', age: 49, city: 'Virginia Beach' },
                { name: 'Avery', age: 10, city: 'Atlanta' },
                { name: 'Matthew', age: 50, city: 'Colorado Springs' },
                { name: 'Ella', age: 9, city: 'Raleigh' },
                { name: 'Aiden', age: 51, city: 'Omaha' },
                { name: 'Scarlett', age: 8, city: 'Miami' },
                { name: 'Logan', age: 52, city: 'Tulsa' },
                { name: 'Victoria', age: 7, city: 'Oakland' },
                { name: 'Jackson', age: 53, city: 'Minneapolis' },
                { name: 'Madison', age: 6, city: 'Tampa' },
                { name: 'David', age: 54, city: 'Cleveland' },
                { name: 'Luna', age: 5, city: 'Wichita' },
                { name: 'Joseph', age: 55, city: 'Arlington' },
                { name: 'Chloe', age: 4, city: 'New Orleans' },
                { name: 'Samuel', age: 56, city: 'Bakersfield' },
                { name: 'Grace', age: 3, city: 'Trenton' },
                { name: 'Gabriel', age: 57, city: 'Cincinnati' },
                { name: 'Lily', age: 2, city: 'Aurora' },
                { name: 'Benjamin', age: 58, city: 'Rochester' },
                { name: 'Aria', age: 1, city: 'Riverside' },
                { name: 'John', age: 30, city: 'New York' },
                { name: 'Jane', age: 25, city: 'Los Angeles' },
                { name: 'Bob', age: 35, city: 'Chicago' },
                { name: 'Alice', age: 28, city: 'Houston' },
                { name: 'Mike', age: 32, city: 'Phoenix' },
                { name: 'Emily', age: 27, city: 'Philadelphia' },
                { name: 'David', age: 31, city: 'San Antonio' },
                { name: 'Sarah', age: 29, city: 'San Diego' },
                { name: 'Chris', age: 33, city: 'Dallas' },
                { name: 'Jessica', age: 26, city: 'San Jose' },
                { name: 'Daniel', age: 34, city: 'Austin' },
                { name: 'Olivia', age: 24, city: 'Jacksonville' },
                { name: 'James', age: 36, city: 'Fort Worth' },
                { name: 'Sophia', age: 23, city: 'Charlotte' },
                { name: 'Andrew', age: 37, city: 'Indianapolis' },
                { name: 'Emma', age: 22, city: 'San Francisco' },
                { name: 'Joseph', age: 38, city: 'Columbus' },
                { name: 'Ava', age: 21, city: 'Detroit' },
                { name: 'William', age: 39, city: 'El Paso' },
                { name: 'Isabella', age: 20, city: 'Memphis' },
                { name: 'Ethan', age: 40, city: 'Seattle' },
                { name: 'Mia', age: 19, city: 'Denver' },
                { name: 'Noah', age: 41, city: 'Washington' },
                { name: 'Charlotte', age: 18, city: 'Boston' },
                { name: 'Liam', age: 42, city: 'Nashville' },
                { name: 'Amelia', age: 17, city: 'Baltimore' },
                { name: 'Benjamin', age: 43, city: 'Louisville' },
                { name: 'Harper', age: 16, city: 'Milwaukee' },
                { name: 'Henry', age: 44, city: 'Portland' },
                { name: 'Evelyn', age: 15, city: 'Las Vegas' },
                { name: 'Alexander', age: 45, city: 'Oklahoma City' },
                { name: 'Abigail', age: 14, city: 'Albuquerque' },
                { name: 'Michael', age: 46, city: 'Tucson' },
                { name: 'Emily', age: 13, city: 'Fresno' },
                { name: 'Elijah', age: 47, city: 'Sacramento' },
                { name: 'Elizabeth', age: 12, city: 'Long Beach' },
                { name: 'James', age: 48, city: 'Kansas City' },
                { name: 'Sofia', age: 11, city: 'Mesa' },
                { name: 'Daniel', age: 49, city: 'Virginia Beach' },
                { name: 'Avery', age: 10, city: 'Atlanta' },
                { name: 'Matthew', age: 50, city: 'Colorado Springs' },
                { name: 'Ella', age: 9, city: 'Raleigh' },
                { name: 'Aiden', age: 51, city: 'Omaha' },
                { name: 'Scarlett', age: 8, city: 'Miami' },
                { name: 'Logan', age: 52, city: 'Tulsa' },
                { name: 'Victoria', age: 7, city: 'Oakland' },
                { name: 'Jackson', age: 53, city: 'Minneapolis' },
                { name: 'Madison', age: 6, city: 'Tampa' },
                { name: 'David', age: 54, city: 'Cleveland' },
                { name: 'Luna', age: 5, city: 'Wichita' },
                { name: 'Joseph', age: 55, city: 'Arlington' },
                { name: 'Chloe', age: 4, city: 'New Orleans' },
                { name: 'Samuel', age: 56, city: 'Bakersfield' },
                { name: 'Grace', age: 3, city: 'Trenton' },
                { name: 'Gabriel', age: 57, city: 'Cincinnati' },
                { name: 'Lily', age: 2, city: 'Aurora' },
                { name: 'Benjamin', age: 58, city: 'Rochester' },
                { name: 'Aria', age: 1, city: 'Riverside' },
                { name: 'John', age: 30, city: 'New York' },
                { name: 'Jane', age: 25, city: 'Los Angeles' },
                { name: 'Bob', age: 35, city: 'Chicago' },
                { name: 'Alice', age: 28, city: 'Houston' },
                { name: 'Mike', age: 32, city: 'Phoenix' },
                { name: 'Emily', age: 27, city: 'Philadelphia' },
                { name: 'David', age: 31, city: 'San Antonio' },
                { name: 'Sarah', age: 29, city: 'San Diego' },
                { name: 'Chris', age: 33, city: 'Dallas' },
                { name: 'Jessica', age: 26, city: 'San Jose' },
                { name: 'Daniel', age: 34, city: 'Austin' },
                { name: 'Olivia', age: 24, city: 'Jacksonville' },
                { name: 'James', age: 36, city: 'Fort Worth' },
                { name: 'Sophia', age: 23, city: 'Charlotte' },
                { name: 'Andrew', age: 37, city: 'Indianapolis' },
                { name: 'Emma', age: 22, city: 'San Francisco' },
                { name: 'Joseph', age: 38, city: 'Columbus' },
                { name: 'Ava', age: 21, city: 'Detroit' },
                { name: 'William', age: 39, city: 'El Paso' },
                { name: 'Isabella', age: 20, city: 'Memphis' },
                { name: 'Ethan', age: 40, city: 'Seattle' },
                { name: 'Mia', age: 19, city: 'Denver' },
                { name: 'Noah', age: 41, city: 'Washington' },
                { name: 'Charlotte', age: 18, city: 'Boston' },
                { name: 'Liam', age: 42, city: 'Nashville' },
                { name: 'Amelia', age: 17, city: 'Baltimore' },
                { name: 'Benjamin', age: 43, city: 'Louisville' },
                { name: 'Harper', age: 16, city: 'Milwaukee' },
                { name: 'Henry', age: 44, city: 'Portland' },
                { name: 'Evelyn', age: 15, city: 'Las Vegas' },
                { name: 'Alexander', age: 45, city: 'Oklahoma City' },
                { name: 'Abigail', age: 14, city: 'Albuquerque' },
                { name: 'Michael', age: 46, city: 'Tucson' },
                { name: 'Emily', age: 13, city: 'Fresno' },
                { name: 'Elijah', age: 47, city: 'Sacramento' },
                { name: 'Elizabeth', age: 12, city: 'Long Beach' },
                { name: 'James', age: 48, city: 'Kansas City' },
                { name: 'Sofia', age: 11, city: 'Mesa' },
                { name: 'Daniel', age: 49, city: 'Virginia Beach' },
                { name: 'Avery', age: 10, city: 'Atlanta' },
                { name: 'Matthew', age: 50, city: 'Colorado Springs' },
                { name: 'Ella', age: 9, city: 'Raleigh' },
                { name: 'Aiden', age: 51, city: 'Omaha' },
                { name: 'Scarlett', age: 8, city: 'Miami' },
                { name: 'Logan', age: 52, city: 'Tulsa' },
                { name: 'Victoria', age: 7, city: 'Oakland' },
                { name: 'Jackson', age: 53, city: 'Minneapolis' },
                { name: 'Madison', age: 6, city: 'Tampa' },
                { name: 'David', age: 54, city: 'Cleveland' },
                { name: 'Luna', age: 5, city: 'Wichita' },
                { name: 'Joseph', age: 55, city: 'Arlington' },
                { name: 'Chloe', age: 4, city: 'New Orleans' },
                { name: 'Samuel', age: 56, city: 'Bakersfield' },
                { name: 'Grace', age: 3, city: 'Trenton' },
                { name: 'Gabriel', age: 57, city: 'Cincinnati' },
                { name: 'Lily', age: 2, city: 'Aurora' },
                { name: 'Benjamin', age: 58, city: 'Rochester' },
                { name: 'Aria', age: 1, city: 'Riverside' },
                { name: 'John', age: 30, city: 'New York' },
                { name: 'Jane', age: 25, city: 'Los Angeles' },
                { name: 'Bob', age: 35, city: 'Chicago' },
                { name: 'Alice', age: 28, city: 'Houston' },
                { name: 'Mike', age: 32, city: 'Phoenix' },
                { name: 'Emily', age: 27, city: 'Philadelphia' },
                { name: 'David', age: 31, city: 'San Antonio' },
                { name: 'Sarah', age: 29, city: 'San Diego' },
                { name: 'Chris', age: 33, city: 'Dallas' },
                { name: 'Jessica', age: 26, city: 'San Jose' },
                { name: 'Daniel', age: 34, city: 'Austin' },
                { name: 'Olivia', age: 24, city: 'Jacksonville' },
                { name: 'James', age: 36, city: 'Fort Worth' },
                { name: 'Sophia', age: 23, city: 'Charlotte' },
                { name: 'Andrew', age: 37, city: 'Indianapolis' },
                { name: 'Emma', age: 22, city: 'San Francisco' },
                { name: 'Joseph', age: 38, city: 'Columbus' },
                { name: 'Ava', age: 21, city: 'Detroit' },
                { name: 'William', age: 39, city: 'El Paso' },
                { name: 'Isabella', age: 20, city: 'Memphis' },
                { name: 'Ethan', age: 40, city: 'Seattle' },
                { name: 'Mia', age: 19, city: 'Denver' },
                { name: 'Noah', age: 41, city: 'Washington' },
                { name: 'Charlotte', age: 18, city: 'Boston' },
                { name: 'Liam', age: 42, city: 'Nashville' },
                { name: 'Amelia', age: 17, city: 'Baltimore' },
                { name: 'Benjamin', age: 43, city: 'Louisville' },
                { name: 'Harper', age: 16, city: 'Milwaukee' },
                { name: 'Henry', age: 44, city: 'Portland' },
                { name: 'Evelyn', age: 15, city: 'Las Vegas' },
                { name: 'Alexander', age: 45, city: 'Oklahoma City' },
                { name: 'Abigail', age: 14, city: 'Albuquerque' },
                { name: 'Michael', age: 46, city: 'Tucson' },
                { name: 'Emily', age: 13, city: 'Fresno' },
                { name: 'Elijah', age: 47, city: 'Sacramento' },
                { name: 'Elizabeth', age: 12, city: 'Long Beach' },
                { name: 'James', age: 48, city: 'Kansas City' },
                { name: 'Sofia', age: 11, city: 'Mesa' },
                { name: 'Daniel', age: 49, city: 'Virginia Beach' },
                { name: 'Avery', age: 10, city: 'Atlanta' },
                { name: 'Matthew', age: 50, city: 'Colorado Springs' },
                { name: 'Ella', age: 9, city: 'Raleigh' },
                { name: 'Aiden', age: 51, city: 'Omaha' },
                { name: 'Scarlett', age: 8, city: 'Miami' },
                { name: 'Logan', age: 52, city: 'Tulsa' },
                { name: 'Victoria', age: 7, city: 'Oakland' },
                { name: 'Jackson', age: 53, city: 'Minneapolis' },
                { name: 'Madison', age: 6, city: 'Tampa' },
                { name: 'David', age: 54, city: 'Cleveland' },
                { name: 'Luna', age: 5, city: 'Wichita' },
                { name: 'Joseph', age: 55, city: 'Arlington' },
                { name: 'Chloe', age: 4, city: 'New Orleans' },
                { name: 'Samuel', age: 56, city: 'Bakersfield' },
                { name: 'Grace', age: 3, city: 'Trenton' },
                { name: 'Gabriel', age: 57, city: 'Cincinnati' },
                { name: 'Lily', age: 2, city: 'Aurora' },
                { name: 'Benjamin', age: 58, city: 'Rochester' },
                { name: 'Aria', age: 1, city: 'Riverside' },
                { name: 'John', age: 30, city: 'New York' },
                { name: 'Jane', age: 25, city: 'Los Angeles' },
                { name: 'Bob', age: 35, city: 'Chicago' },
                { name: 'Alice', age: 28, city: 'Houston' },
                { name: 'Mike', age: 32, city: 'Phoenix' },
                { name: 'Emily', age: 27, city: 'Philadelphia' },
                { name: 'David', age: 31, city: 'San Antonio' },
                { name: 'Sarah', age: 29, city: 'San Diego' },
                { name: 'Chris', age: 33, city: 'Dallas' },
                { name: 'Jessica', age: 26, city: 'San Jose' },
                { name: 'Daniel', age: 34, city: 'Austin' },
                { name: 'Olivia', age: 24, city: 'Jacksonville' },
                { name: 'James', age: 36, city: 'Fort Worth' },
                { name: 'Sophia', age: 23, city: 'Charlotte' },
                { name: 'Andrew', age: 37, city: 'Indianapolis' },
                { name: 'Emma', age: 22, city: 'San Francisco' },
                { name: 'Joseph', age: 38, city: 'Columbus' },
                { name: 'Ava', age: 21, city: 'Detroit' },
                { name: 'William', age: 39, city: 'El Paso' },
                { name: 'Isabella', age: 20, city: 'Memphis' },
                { name: 'Ethan', age: 40, city: 'Seattle' },
                { name: 'Mia', age: 19, city: 'Denver' },
                { name: 'Noah', age: 41, city: 'Washington' },
                { name: 'Charlotte', age: 18, city: 'Boston' },
                { name: 'Liam', age: 42, city: 'Nashville' },
                { name: 'Amelia', age: 17, city: 'Baltimore' },
                { name: 'Benjamin', age: 43, city: 'Louisville' },
                { name: 'Harper', age: 16, city: 'Milwaukee' },
                { name: 'Henry', age: 44, city: 'Portland' },
                { name: 'Evelyn', age: 15, city: 'Las Vegas' },
                { name: 'Alexander', age: 45, city: 'Oklahoma City' },
                { name: 'Abigail', age: 14, city: 'Albuquerque' },
                { name: 'Michael', age: 46, city: 'Tucson' },
                { name: 'Emily', age: 13, city: 'Fresno' },
                { name: 'Elijah', age: 47, city: 'Sacramento' },
                { name: 'Elizabeth', age: 12, city: 'Long Beach' },
                { name: 'James', age: 48, city: 'Kansas City' },
                { name: 'Sofia', age: 11, city: 'Mesa' },
                { name: 'Daniel', age: 49, city: 'Virginia Beach' },
                { name: 'Avery', age: 10, city: 'Atlanta' },
                { name: 'Matthew', age: 50, city: 'Colorado Springs' },
                { name: 'Ella', age: 9, city: 'Raleigh' },
                { name: 'Aiden', age: 51, city: 'Omaha' },
                { name: 'Scarlett', age: 8, city: 'Miami' },
                { name: 'Logan', age: 52, city: 'Tulsa' },
                { name: 'Victoria', age: 7, city: 'Oakland' },
                { name: 'Jackson', age: 53, city: 'Minneapolis' },
                { name: 'Madison', age: 6, city: 'Tampa' },
                { name: 'David', age: 54, city: 'Cleveland' },
                { name: 'Luna', age: 5, city: 'Wichita' },
                { name: 'Joseph', age: 55, city: 'Arlington' },
                { name: 'Chloe', age: 4, city: 'New Orleans' },
                { name: 'Samuel', age: 56, city: 'Bakersfield' },
                { name: 'Grace', age: 3, city: 'Trenton' },
                { name: 'Gabriel', age: 57, city: 'Cincinnati' },
                { name: 'Lily', age: 2, city: 'Aurora' },
                { name: 'Benjamin', age: 58, city: 'Rochester' },
                { name: 'Aria', age: 1, city: 'Riverside' },
                { name: 'John', age: 30, city: 'New York' },
                { name: 'Jane', age: 25, city: 'Los Angeles' },
                { name: 'Bob', age: 35, city: 'Chicago' },
                { name: 'Alice', age: 28, city: 'Houston' },
                { name: 'Mike', age: 32, city: 'Phoenix' },
                { name: 'Emily', age: 27, city: 'Philadelphia' },
                { name: 'David', age: 31, city: 'San Antonio' },
                { name: 'Sarah', age: 29, city: 'San Diego' },
                { name: 'Chris', age: 33, city: 'Dallas' },
                { name: 'Jessica', age: 26, city: 'San Jose' },
                { name: 'Daniel', age: 34, city: 'Austin' },
                { name: 'Olivia', age: 24, city: 'Jacksonville' },
                { name: 'James', age: 36, city: 'Fort Worth' },
                { name: 'Sophia', age: 23, city: 'Charlotte' },
                { name: 'Andrew', age: 37, city: 'Indianapolis' },
                { name: 'Emma', age: 22, city: 'San Francisco' },
                { name: 'Joseph', age: 38, city: 'Columbus' },
                { name: 'Ava', age: 21, city: 'Detroit' },
                { name: 'William', age: 39, city: 'El Paso' },
                { name: 'Isabella', age: 20, city: 'Memphis' },
                { name: 'Ethan', age: 40, city: 'Seattle' },
                { name: 'Mia', age: 19, city: 'Denver' },
                { name: 'Noah', age: 41, city: 'Washington' },
                { name: 'Charlotte', age: 18, city: 'Boston' },
                { name: 'Liam', age: 42, city: 'Nashville' },
                { name: 'Amelia', age: 17, city: 'Baltimore' },
                { name: 'Benjamin', age: 43, city: 'Louisville' },
                { name: 'Harper', age: 16, city: 'Milwaukee' },
                { name: 'Henry', age: 44, city: 'Portland' },
                { name: 'Evelyn', age: 15, city: 'Las Vegas' },
                { name: 'Alexander', age: 45, city: 'Oklahoma City' },
                { name: 'Abigail', age: 14, city: 'Albuquerque' },
                { name: 'Michael', age: 46, city: 'Tucson' },
                { name: 'Emily', age: 13, city: 'Fresno' },
                { name: 'Elijah', age: 47, city: 'Sacramento' },
                { name: 'Elizabeth', age: 12, city: 'Long Beach' },
                { name: 'James', age: 48, city: 'Kansas City' },
                { name: 'Sofia', age: 11, city: 'Mesa' },
                { name: 'Daniel', age: 49, city: 'Virginia Beach' },
                { name: 'Avery', age: 10, city: 'Atlanta' },
                { name: 'Matthew', age: 50, city: 'Colorado Springs' },
                { name: 'Ella', age: 9, city: 'Raleigh' },
                { name: 'Aiden', age: 51, city: 'Omaha' },
                { name: 'Scarlett', age: 8, city: 'Miami' },
                { name: 'Logan', age: 52, city: 'Tulsa' },
                { name: 'Victoria', age: 7, city: 'Oakland' },
                { name: 'Jackson', age: 53, city: 'Minneapolis' },
                { name: 'Madison', age: 6, city: 'Tampa' },
                { name: 'David', age: 54, city: 'Cleveland' },
                { name: 'Luna', age: 5, city: 'Wichita' },
                { name: 'Joseph', age: 55, city: 'Arlington' },
                { name: 'Chloe', age: 4, city: 'New Orleans' },
                { name: 'Samuel', age: 56, city: 'Bakersfield' },
                { name: 'Grace', age: 3, city: 'Trenton' },
                { name: 'Gabriel', age: 57, city: 'Cincinnati' },
                { name: 'Lily', age: 2, city: 'Aurora' },
                { name: 'Benjamin', age: 58, city: 'Rochester' },
                { name: 'Aria', age: 1, city: 'Riverside' }
            ],
            rowNum: 0,
            column: 4
        };
    },
    methods: {
        // exportToPdf() {
        //     const content = this.$refs.content;
        //     html2canvas(content, {
        //         useCORS: true, //允许canvas画布内可以跨域请求外部链接图片, 允许跨域请求。
        //         dpi: 300, // 提升导出的文件的分辨率
        //         scale: 2 // 提升导出的文件的分辨率
        //     }).then((canvas) => {
        //         const imgData = canvas.toDataURL('image/png');
        //         // ('image/jpeg', 1.0)
        //         const pdf = new jsPDF({
        //             orientation: 'p',
        //             unit: 'pt',
        //             format: 'a4'
        //         });
        //         const imgProps = pdf.getImageProperties(imgData);
        //         const pdfWidth = pdf.internal.pageSize.getWidth();
        //         const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
        //         console.log('页面总高度', pdfHeight);
        //         let heightLeft = pdfHeight;
        //
        //         const pageHeight = pdf.internal.pageSize.getHeight() - 20;
        //         console.log('每页高度', pageHeight);
        //         let x = 0;
        //         let y = 0;
        //         // 分页
        //         while (heightLeft >= 0) {
        //             console.log(x, y, pdfWidth, pageHeight);
        //             pdf.addImage(imgData, 'PNG', x, y, pdfWidth, pageHeight);
        //             heightLeft -= pageHeight;
        //             y += pageHeight;
        //             if (heightLeft >= 0) {
        //                 pdf.addPage();
        //             }
        //         }
        //         pdf.save('PDF数据.pdf');
        //     });
        // },
        exportToPdf() {
            this.$nextTick(() => {
                htmlToPdf('content', 'PDF数据');
            });
        },
        exportPdf() {
            this.$nextTick(() => {
                exportToPDF('#content', 'PDF数据');
            });
        },
        downloadPDF() {
            this.$nextTick(() => {
                downloadPDF(this.$refs.content.innerHTML, 'PDF数据');
            });
        },
        initChart() {
            // 初始化echarts图表
            const chart = echarts.init(document.getElementById('chart'));
            // 配置折线图
            const option = {
                title: {
                    text: 'Echarts Chart Example'
                },
                tooltip: {},
                legend: {
                    data: ['Sales']
                },
                xAxis: {
                    data: ['Shirt', 'Cardigan', 'Chiffon shirt', 'Pants', 'High heels', 'Socks']
                },
                yAxis: {},
                series: [
                    {
                        name: 'Sales',
                        type: 'bar',
                        data: [5, 20, 36, 10, 10, 20]
                    }
                ]
            };
            chart.setOption(option);
        },
        initData() {
            console.log(this.tableData.length);
            this.rowNum = Math.ceil(this.tableData.length / this.column);
            console.log(this.rowNum);
        }
    },
    mounted() {
        // 在组件挂载后初始化图表
        this.initChart();
        // 初始化数据
        this.initData();
    }
};
</script>

<template>
    <div class="HtmlToPDF">
        <button @click="exportToPdf">下载PDF</button>
        <button @click="exportPdf">下载PDF</button>
        <button @click="downloadPDF">下载PDF</button>
        <div ref="content" id="content" class="content">
            <!--echarts图表-->
            <div id="chart" ref="chart" style="width: 100%; height: 800px"></div>
            <!--表格-->
            <div ref="table" class="table-box" style="display: flex; flex-wrap: wrap; gap: 5px; justify-content: space-between">
                <table v-for="i in column" :key="i">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>姓名</th>
                            <th>年龄</th>
                            <th>城市</th>
                        </tr>
                    </thead>
                    <tbody>
                        <template v-for="(item, index) in tableData" :key="index">
                            <tr v-if="index < i * rowNum && index >= (i - 1) * rowNum">
                                <td>{{ index + 1 }}</td>
                                <td>{{ item.name }}</td>
                                <td>{{ item.age }}</td>
                                <td>{{ item.city }}</td>
                            </tr>
                        </template>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
.content {
    padding: 20px;
}
.table-box {
    table {
        margin-bottom: 20px;
        border-collapse: collapse;
        border: 1px solid #ccc;
        thead {
            tr {
                th {
                    background-color: #f5f5f5;
                    border: 1px solid #ccc;
                    padding: 10px;
                    text-align: center;
                }
            }
        }
        tbody {
            tr {
                &:nth-child(odd) {
                    background-color: #f9f9f9;
                }
                &:nth-child(even) {
                    background-color: #fff;
                }
                td {
                    border: 1px solid #ccc;
                    padding: 10px;
                    text-align: center;
                }
            }
        }
    }
}
</style>
